package com.usefullc.extinguisher.service.dataTransfer;

import com.usefullc.common.util.BeanUtils;
import com.usefullc.common.util.DateUtils;
import com.usefullc.common.util.JsonUtil;
import com.usefullc.common.util.date.DatePattern;
import com.usefullc.common.util.date.DateTimePattern;
import com.usefullc.extinguisher.domain.FireDevice;
import com.usefullc.extinguisher.service.FireDeviceService;
import com.usefullc.extinguisher.vo.FireDeviceVo;
import com.usefullc.system.domain.DataDict;
import com.usefullc.system.service.DataDictService;
import com.usefullc.user.domain.User;
import com.usefullc.user.enums.UserGenderEnum;
import com.usefullc.user.param.UserEditParam;
import com.usefullc.user.param.UserLoginByBindParam;
import com.usefullc.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.File;
import java.util.*;

/**
 * @author: Sampson
 * @date: 2022-09-11 12:09
 */
@Slf4j
@Service
public class DataTransferService {

    private List<DevicePosition> firstDataList = new ArrayList<>();

    @Autowired
    private DataDictService dataDictService;

    @Autowired
    private UserService userService;

    @Autowired
    private FireDeviceService fireDeviceService;


    public void saveDeviceDataDict(){
        init();
//        long firstParentId = 96;
        int index = 1;
        for (DevicePosition devicePosition : firstDataList) {
            DataDict dataDict1 = new DataDict();
            dataDict1.setAppName("extinguisher");
            dataDict1.setTenantId(1L);
            dataDict1.setName(devicePosition.getText());
            dataDict1.setValue(""+devicePosition.getValue());
            dataDict1.setType(0);
            dataDict1.setParentId(91L);
            dataDict1.setOrderNo(index);
            dataDict1.setDescription(devicePosition.getText());
            dataDictService.saveDataDict(dataDict1);
            index++;

            //二级
            List<DevicePosition> childList = devicePosition.getChildList();
            int orderNo = 1;
            for (DevicePosition position : childList) {
                DataDict dataDict = new DataDict();
                dataDict.setAppName("extinguisher");
                dataDict.setTenantId(1L);
                dataDict.setName(position.getText());
                dataDict.setValue(""+position.getValue());
                dataDict.setType(0);
                dataDict.setParentId(dataDict1.getId());
                dataDict.setOrderNo(orderNo);
                dataDict.setDescription(position.getText());
                dataDictService.saveDataDict(dataDict);
                orderNo++;
//                firstParentId++;

                //三级
                int thirdOrderNo = 1;
                List<DevicePosition> thirdChildList = position.getChildList();
                for (DevicePosition thirdPosition : thirdChildList) {

                    DataDict dataDict3 = new DataDict();
                    dataDict3.setAppName("extinguisher");
                    dataDict3.setTenantId(1L);
                    dataDict3.setName(thirdPosition.getText());
                    dataDict3.setValue(""+thirdPosition.getValue());
                    dataDict3.setType(0);
                    dataDict3.setParentId(dataDict.getId());
                    dataDict3.setOrderNo(thirdOrderNo);
                    String description3 = dataDict1.getValue()+","+dataDict.getValue()+","+dataDict3.getValue();
                    dataDict3.setDescription(description3);
                    dataDictService.saveDataDict(dataDict3);
                    thirdOrderNo++;
                }


            }

        }



    }

    public static void main(String[] args) {
        DataTransferService dataTransferService = new DataTransferService();
        dataTransferService.init();
        System.out.println(dataTransferService.firstDataList);





    }


    public void init(){
        firstDataList.clear();
        String manufacturerItemList = "秦一厂,秦二厂,秦三厂,方家山,非生产区域";
        String[] firstArray = manufacturerItemList.split(",");

        String areaItemList = "要害区,保护区,控制区,1 2#要害区,1 2#保护区,1 2#控制区,3 4#要害区,3 4#保护区,一厂非生产,方家山非生产,二厂非生产";
        String[] secondArray = areaItemList.split(",");


        String positionItemList = "01#反应堆厂房,02#一回路辅助厂房,03#燃料厂房,04#汽轮发电机厂房,05#主控厂房,49#-3,次氯酸钠间,06#应急冷冻机厂房,07#应急柴油发电机厂房,71#AAC柴油发电机房,17#化水厂房,32#办公楼,22#固化厂房,油务厂房,机械检修车间,主变区域,16#GIS开关站,01#外集装箱,22#外山坡上集装箱SBO柴油发电机组,09#应急冷冻厂房,10#空压站和检修变,阴极保护站和仪控化学危险品库,电仪楼,水下维修车间,14#电气修理车间,13#机修厂房,12#锅炉房和12#油罐区域,15#电焊车间,23#热车间,21#弱放废物贮存库,24#固化物贮存库和廊道,新建消防泵房和消防水厂房室外棚库,保卫控制中心和控制区出入口,11#土建仓库,集装箱外,1RX,1KX,1WX,1DX,1LX,2RX,2KX,2WX,2DX,2LX,9NX,ET,DU,PX,1MX,2MX,TD（JX),TB,TC,UG,ZC,VA,XL,DY,TH,ZB,AC,AL,QS,QT,QA,QB,QR,FC,HX,1MP,2MP,MO,FS,1ZA,2ZA,GB,集装箱,GA,2TA,1TA,EF2,EF5,PA,EF1,EF4,UA,UD,YA,1NX,2NX,1、2ET,DF,升压站(DF),AN,TE,YK,CC＆CA,GB沟,室外吸烟点,AS,AA1,AB,AD,生产办公楼,UD、EG,EF,新QT,QT2,QT1,环境监测站,3RX,4RX,3KX,4KX,3NX,4NX,3LX,4LX,3DX,4DX,3、4ET,3MX,4MX,YA厂房,8DS厂房,JX,ZC厂房,工程会议室,AC厂房,AM厂房,GD2,指定吸烟点,现场各岗位,1#TB,1#TA,1#SB,1#RB,海水泵房,1#主变,水厂,模拟体,RCW备用厂房,制氢站,次氯酸钠发生站,3#办公楼,2#TB,2#TA,2#主变,2#SB,2#RB,模拟体附属仓库,25辅楼,25主楼,25主楼地下车库,一食堂,25B,停车场,保卫楼,25C,仓库,废物库,乏储,运行支持中心,厂区门卫,29#库,仓库院内,37#库,26#库,AX化学制剂库,31#办公楼,小车队,老保卫处,宣传中心,33#办公楼,综合培训楼,生产培训中心,文档中心,调试大棚,厂区食堂,技能中心,39#-3淡水厂和扩建,高跨和低跨,取水口,排水口,微波站,42#雨水泵房和49#连接厂房及环境检测站,维支材料库,BX,AF,EA,ED,EC-B,OP,AY,CB,EM,气象站,综合楼,综合楼餐厅,办证大厅,设备堆场,EI,BD1,BD,EH,OF,变电所1＆四达,变电所（警戒区）,SA2食堂,SA1食堂,厂区大车库,培教大楼,雨水泵房,保卫处,检修大楼,隧道,新倒班楼,地下车库,BY综合楼,中原建村（128）,观光塔,设备仓库,EW,应急大车库,JM,增压站,危化品库,铆焊车间";
        String[] thirdArray = positionItemList.split(",");

        String categorySecondList ="0,1,2#3,4,5,6,7#1,2#0,1,2#8,9,10";
        String[] secondSlotArray = categorySecondList.split("#");

        String categoryThirdList ="0,1,2,35,36,37,38,39,40,41,42,43,44,45,46,47,48#3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,88,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,164#19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,86,87,152,153,154,155,156,157,158,159,160,161,162,163,164#35,40,36,41,89,90,39,44,91,38,43,48#49,50,92,93,61,94,62,56,55,68,88,65,69,51,95,60,96,97,98,99#53,52,63,100,64,101,102,103,104,105,106,107,108,109,110#111,112,113,114,115,116,117,118,119,120,121,48#122,123,124,98,69,125,126,127,128,129,130,52,60,65,131,132,133#165,166,167,168,169,170,171,172,173,174,163,175,176,177,178,179,180,157,181,182,183,184,185,186,187,188,196,190,194,189,102,228#189,190,102,191,192,193,194,195,196,197,198,199,158,200#201,188,202,203,204,205,178,206,207,208,209,210,211,212,213,214,215,216,217,197,218,219,220,221,222,223,224,164,225,226,195,227";
        String[] thirdSlotArray = categoryThirdList.split("#");

        String realThirdList = "code:12,firstCode:0,secondCode:1#code:134,firstCode:2,secondCode:1#code:117,firstCode:1,secondCode:6#code:142,firstCode:2,secondCode:1#code:18,firstCode:0,secondCode:1#code:155,firstCode:2,secondCode:2#code:169,firstCode:4,secondCode:8#code:226,firstCode:4,secondCode:10#code:74,firstCode:3,secondCode:1#code:170,firstCode:4,secondCode:8#code:225,firstCode:4,secondCode:10#code:154,firstCode:2,secondCode:2#code:47,firstCode:3,secondCode:0#code:38,firstCode:1,secondCode:3#code:38,firstCode:3,secondCode:0#code:14,firstCode:0,secondCode:1#code:166,firstCode:4,secondCode:8#code:78,firstCode:3,secondCode:1#code:133,firstCode:1,secondCode:7#code:101,firstCode:1,secondCode:5#code:116,firstCode:1,secondCode:6#code:4,firstCode:0,secondCode:1#code:106,firstCode:1,secondCode:5#code:30,firstCode:0,secondCode:2#code:151,firstCode:2,secondCode:1#code:109,firstCode:1,secondCode:5#code:135,firstCode:2,secondCode:1#code:53,firstCode:3,secondCode:1#code:219,firstCode:4,secondCode:10#code:97,firstCode:1,secondCode:4#code:53,firstCode:1,secondCode:5#code:23,firstCode:0,secondCode:2#code:98,firstCode:1,secondCode:4#code:121,firstCode:1,secondCode:6#code:80,firstCode:3,secondCode:1#code:152,firstCode:2,secondCode:2#code:195,firstCode:4,secondCode:9#code:192,firstCode:4,secondCode:9#code:179,firstCode:4,secondCode:8#code:113,firstCode:1,secondCode:6#code:218,firstCode:4,secondCode:10#code:221,firstCode:4,secondCode:10#code:176,firstCode:4,secondCode:8#code:140,firstCode:2,secondCode:1#code:93,firstCode:1,secondCode:4#code:16,firstCode:0,secondCode:1#code:19,firstCode:0,secondCode:2#code:96,firstCode:1,secondCode:4#code:144,firstCode:2,secondCode:1#code:24,firstCode:0,secondCode:2#code:89,firstCode:1,secondCode:3#code:196,firstCode:4,secondCode:9#code:94,firstCode:1,secondCode:4#code:201,firstCode:4,secondCode:10#code:46,firstCode:3,secondCode:0#code:189,firstCode:4,secondCode:9#code:209,firstCode:4,secondCode:10#code:17,firstCode:0,secondCode:1#code:52,firstCode:3,secondCode:1#code:2,firstCode:0,secondCode:0#code:49,firstCode:3,secondCode:1#code:224,firstCode:4,secondCode:10#code:52,firstCode:1,secondCode:5#code:84,firstCode:3,secondCode:1#code:156,firstCode:2,secondCode:2#code:129,firstCode:1,secondCode:7#code:175,firstCode:4,secondCode:8#code:88,firstCode:1,secondCode:4#code:188,firstCode:4,secondCode:8#code:88,firstCode:3,secondCode:1#code:149,firstCode:2,secondCode:1#code:199,firstCode:4,secondCode:9#code:7,firstCode:0,secondCode:1#code:43,firstCode:1,secondCode:3#code:49,firstCode:1,secondCode:4#code:178,firstCode:4,secondCode:8#code:43,firstCode:3,secondCode:0#code:34,firstCode:0,secondCode:2#code:20,firstCode:0,secondCode:2#code:70,firstCode:3,secondCode:1#code:180,firstCode:4,secondCode:8#code:10,firstCode:0,secondCode:1#code:158,firstCode:4,secondCode:9#code:158,firstCode:2,secondCode:2#code:87,firstCode:3,secondCode:2#code:165,firstCode:4,secondCode:8#code:91,firstCode:1,secondCode:3#code:13,firstCode:2,secondCode:1#code:75,firstCode:3,secondCode:1#code:13,firstCode:0,secondCode:1#code:22,firstCode:0,secondCode:2#code:182,firstCode:4,secondCode:8#code:124,firstCode:1,secondCode:7#code:77,firstCode:3,secondCode:1#code:25,firstCode:0,secondCode:2#code:55,firstCode:1,secondCode:4#code:127,firstCode:1,secondCode:7#code:55,firstCode:3,secondCode:1#code:191,firstCode:4,secondCode:9#code:6,firstCode:0,secondCode:1#code:3,firstCode:0,secondCode:1#code:21,firstCode:0,secondCode:2#code:104,firstCode:1,secondCode:5#code:197,firstCode:4,secondCode:9#code:172,firstCode:4,secondCode:8#code:81,firstCode:3,secondCode:1#code:159,firstCode:2,secondCode:2#code:90,firstCode:1,secondCode:3#code:139,firstCode:2,secondCode:1#code:37,firstCode:3,secondCode:0#code:69,firstCode:1,secondCode:4#code:177,firstCode:4,secondCode:8#code:220,firstCode:4,secondCode:10#code:160,firstCode:2,secondCode:2#code:136,firstCode:2,secondCode:1#code:69,firstCode:3,secondCode:1#code:217,firstCode:4,secondCode:10#code:125,firstCode:1,secondCode:7#code:110,firstCode:1,secondCode:5#code:212,firstCode:4,secondCode:10#code:11,firstCode:0,secondCode:1#code:35,firstCode:1,secondCode:3#code:145,firstCode:2,secondCode:1#code:150,firstCode:2,secondCode:1#code:35,firstCode:3,secondCode:0#code:72,firstCode:3,secondCode:1#code:60,firstCode:1,secondCode:4#code:79,firstCode:3,secondCode:1#code:60,firstCode:3,secondCode:1#code:200,firstCode:4,secondCode:9#code:207,firstCode:4,secondCode:10#code:108,firstCode:1,secondCode:5#code:141,firstCode:2,secondCode:1#code:163,firstCode:4,secondCode:8#code:62,firstCode:3,secondCode:1#code:33,firstCode:0,secondCode:2#code:62,firstCode:1,secondCode:4#code:198,firstCode:4,secondCode:9#code:103,firstCode:1,secondCode:5#code:29,firstCode:0,secondCode:2#code:163,firstCode:2,secondCode:2#code:59,firstCode:3,secondCode:1#code:68,firstCode:1,secondCode:4#code:68,firstCode:3,secondCode:1#code:210,firstCode:4,secondCode:10#code:114,firstCode:1,secondCode:6#code:130,firstCode:1,secondCode:7#code:119,firstCode:1,secondCode:6#code:5,firstCode:0,secondCode:1#code:39,firstCode:3,secondCode:0#code:58,firstCode:3,secondCode:1#code:211,firstCode:4,secondCode:10#code:50,firstCode:1,secondCode:4#code:148,firstCode:2,secondCode:1#code:183,firstCode:4,secondCode:8#code:71,firstCode:3,secondCode:1#code:9,firstCode:0,secondCode:1#code:64,firstCode:3,secondCode:1#code:138,firstCode:2,secondCode:1#code:64,firstCode:1,secondCode:5#code:146,firstCode:2,secondCode:1#code:50,firstCode:3,secondCode:1#code:105,firstCode:1,secondCode:5#code:39,firstCode:1,secondCode:3#code:186,firstCode:4,secondCode:8#code:174,firstCode:4,secondCode:8#code:184,firstCode:4,secondCode:8#code:83,firstCode:3,secondCode:1#code:27,firstCode:0,secondCode:2#code:185,firstCode:4,secondCode:8#code:51,firstCode:3,secondCode:1#code:36,firstCode:1,secondCode:3#code:137,firstCode:2,secondCode:1#code:51,firstCode:1,secondCode:4#code:36,firstCode:3,secondCode:0#code:61,firstCode:3,secondCode:1#code:61,firstCode:1,secondCode:4#code:40,firstCode:3,secondCode:0#code:85,firstCode:3,secondCode:1#code:8,firstCode:0,secondCode:1#code:40,firstCode:1,secondCode:3#code:164,firstCode:4,secondCode:10#code:164,firstCode:2,secondCode:2#code:132,firstCode:1,secondCode:7#code:143,firstCode:2,secondCode:1#code:31,firstCode:0,secondCode:2#code:99,firstCode:1,secondCode:4#code:161,firstCode:2,secondCode:2#code:115,firstCode:1,secondCode:6#code:181,firstCode:4,secondCode:8#code:73,firstCode:3,secondCode:1#code:28,firstCode:0,secondCode:2#code:86,firstCode:3,secondCode:2#code:167,firstCode:4,secondCode:8#code:204,firstCode:4,secondCode:10#code:162,firstCode:2,secondCode:2#code:42,firstCode:3,secondCode:0#code:131,firstCode:1,secondCode:7#code:214,firstCode:4,secondCode:10#code:63,firstCode:3,secondCode:1#code:190,firstCode:4,secondCode:9#code:63,firstCode:1,secondCode:5#code:118,firstCode:1,secondCode:6#code:193,firstCode:4,secondCode:9#code:168,firstCode:4,secondCode:8#code:187,firstCode:4,secondCode:8#code:202,firstCode:4,secondCode:10#code:100,firstCode:1,secondCode:5#code:157,firstCode:4,secondCode:8#code:157,firstCode:2,secondCode:2#code:57,firstCode:3,secondCode:1#code:15,firstCode:0,secondCode:1#code:82,firstCode:3,secondCode:1#code:120,firstCode:1,secondCode:6#code:102,firstCode:4,secondCode:9#code:102,firstCode:1,secondCode:5#code:153,firstCode:2,secondCode:2#code:44,firstCode:1,secondCode:3#code:44,firstCode:3,secondCode:0#code:48,firstCode:3,secondCode:0#code:48,firstCode:1,secondCode:3#code:66,firstCode:3,secondCode:1#code:227,firstCode:4,secondCode:10#code:126,firstCode:1,secondCode:7#code:122,firstCode:1,secondCode:7#code:92,firstCode:1,secondCode:4#code:112,firstCode:1,secondCode:6#code:67,firstCode:3,secondCode:1#code:56,firstCode:1,secondCode:4#code:26,firstCode:0,secondCode:2#code:56,firstCode:3,secondCode:1#code:205,firstCode:4,secondCode:10#code:222,firstCode:4,secondCode:10#code:95,firstCode:1,secondCode:4#code:32,firstCode:0,secondCode:2#code:223,firstCode:4,secondCode:10#code:215,firstCode:4,secondCode:10#code:0,firstCode:0,secondCode:0#code:123,firstCode:1,secondCode:7#code:173,firstCode:4,secondCode:8#code:171,firstCode:4,secondCode:8#code:216,firstCode:4,secondCode:10#code:107,firstCode:1,secondCode:5#code:111,firstCode:1,secondCode:6#code:54,firstCode:3,secondCode:1#code:65,firstCode:3,secondCode:1#code:208,firstCode:4,secondCode:10#code:203,firstCode:4,secondCode:10#code:65,firstCode:1,secondCode:4#code:206,firstCode:4,secondCode:10#code:228,firstCode:4,secondCode:8#code:76,firstCode:3,secondCode:1#code:1,firstCode:0,secondCode:0#code:194,firstCode:4,secondCode:9#code:41,firstCode:1,secondCode:3#code:41,firstCode:3,secondCode:0#code:147,firstCode:2,secondCode:1#code:213,firstCode:4,secondCode:10#code:128,firstCode:1,secondCode:7#code:45,firstCode:3,secondCode:0";


        String[] realThirdArray = realThirdList.split("#");

        for (int i = 0; i < firstArray.length; i++) {
            String text = firstArray[i];
            DevicePosition devicePosition = new DevicePosition();
            devicePosition.setText(text);
            devicePosition.setValue(i);
            firstDataList.add(devicePosition);

            List<DevicePosition> childList = new ArrayList<>();
            devicePosition.setChildList(childList);

            //二级
            String ss = secondSlotArray[i];
            String[] ssArray = ss.split(",");
            for (int i2 = 0; i2 < ssArray.length; i2++) {
               int ssIndex = Integer.valueOf(ssArray[i2]);
//            }
//            for (int i2 = 0; i2 < secondArray.length; i2++) {
                String secondText = secondArray[ssIndex];
                DevicePosition secondDevicePosition = new DevicePosition();
                secondDevicePosition.setText(secondText);
                secondDevicePosition.setValue(ssIndex);
                childList.add(secondDevicePosition);

                List<DevicePosition> thirdChildList = new ArrayList<>();
                secondDevicePosition.setChildList(thirdChildList);
                //三级
                String ts = thirdSlotArray[ssIndex];
                String[] tsArray = ts.split(",");
                for (int i3 = 0; i3 < tsArray.length; i3++) {
                    int tsIndex = Integer.valueOf(tsArray[i3]);
                    for (String s : realThirdArray) {
                        String[] realThirdS = s.split(",");
                        if (realThirdS[0].split(":")[1].equalsIgnoreCase(""+tsIndex) && realThirdS[1].split(":")[1].equalsIgnoreCase(""+i) &&
                                realThirdS[2].split(":")[1].equalsIgnoreCase(""+ssIndex)) {
                            String thirdText = thirdArray[tsIndex];
                            DevicePosition thirdDevicePosition = new DevicePosition();
                            thirdDevicePosition.setText(thirdText);
                            thirdDevicePosition.setValue(tsIndex);
                            thirdChildList.add(thirdDevicePosition);
                            break;
                        }
                    }


                }

            }
        }



    }

    public void userFromJosnToDB(){
        try{

            File userIdsFile = new File("/Users/long3/Documents/extinguisher/user.txt");
            FileUtils.touch(userIdsFile);
            List<DataDict> fireDevicePositionList = dataDictService.getChildrenByCodeLike("0027");
            Map<String,String> dataDictMap = new HashMap<>();
            for (DataDict dataDict : fireDevicePositionList) {
                dataDictMap.put(dataDict.getDescription(),dataDict.getCode());

            }
//            Map<String, String> dataDictMap = fireDevicePositionList.stream().collect(Collectors.toMap(DataDict::getDescription, DataDict::getCode));


            List<String> strings = FileUtils.readLines(new File("/Users/long3/Documents/extinguisher/user.json"), "utf-8");

            List<String> ids = new ArrayList<>();
            for (String string : strings) {
                HashMap<String, Object> jsonMap = JsonUtil.json2ObjectMap(string);
                UserLoginByBindParam param = new UserLoginByBindParam();
                Object openId = jsonMap.get("_openid");
                param.setDeviceId(new Date().toString());
                param.setBindType(0);
                param.setOpenId(openId.toString());
                param.setAvatar(jsonMap.get("avatar").toString());
                param.setNickname(jsonMap.get("nickname").toString());
                User user = userService.loginByBind(param);

                Object status = jsonMap.get("status");
                Object role = jsonMap.get("role");
                Integer statusInt = Double.valueOf(status.toString()).intValue();
                Integer roleInt = Double.valueOf(role.toString()).intValue();
                user.setStatus(statusInt);
                user.setTenantId(1L);
                user.setGender(UserGenderEnum.MALE.getCode());


                String _id = jsonMap.get("_id").toString();
                ids.add(_id+","+user.getId().toString());


                UserEditParam userEditParam = new UserEditParam();
                List<Long> roleIds = new ArrayList<>();
                if(roleInt == 0){
                    roleIds.add(2L);
                }else {
                    roleIds.add(4L);
                }
                userEditParam.setRoleIds(roleIds);

                userService.saveUser(user,userEditParam);


            }
            FileUtils.writeLines(userIdsFile,ids);



        }catch (Exception e){
            e.printStackTrace();
        }


    }


    @Transactional
    public void deviceFromJsonToDB() {
        int dirtyCount = 0;
        int repeatCount = 0;
        try{
            List<DataDict> fireDevicePositionList = dataDictService.getChildrenByCodeLike("0027");
            Map<String,String> dataDictMap = new HashMap<>();
            for (DataDict dataDict : fireDevicePositionList) {
                dataDictMap.put(dataDict.getDescription(),dataDict.getCode());

            }
            File userIdsFile = new File("/Users/long3/Documents/extinguisher/user.txt");
            List<String> ids = FileUtils.readLines(userIdsFile, "utf-8");
            Map<String,Long> idMap = new HashMap<>();
            for (String id : ids) {

                idMap.put(id.split(",")[0],Long.valueOf(id.split(",")[1]));
            }
//            Map<String, String> dataDictMap = fireDevicePositionList.stream().collect(Collectors.toMap(DataDict::getDescription, DataDict::getCode));


            List<String> strings = FileUtils.readLines(new File("/Users/long3/Documents/extinguisher/extinguisher.json"), "utf-8");
//        List<FireDevice> fireDeviceList = new ArrayList<>();
            for (String string : strings) {
                HashMap<String, Object> jsonMap = JsonUtil.json2ObjectMap(string);
                FireDevice fireDevice = new FireDevice();
                Object type = jsonMap.get("type");
                if(type != null){
                    fireDevice.setType(Double.valueOf(type.toString()).intValue());
                }else{
                    dirtyCount++;
                    continue;
                }
                Object status = jsonMap.get("status");
                fireDevice.setStatus(Double.valueOf(status.toString()).intValue());

                String key = Double.valueOf(jsonMap.get("manufacturer").toString()).intValue()+","+Double.valueOf(jsonMap.get("area").toString()).intValue()+","+Double.valueOf(jsonMap.get("position").toString()).intValue();
                String position = dataDictMap.get(key);
                if (StringUtils.isEmpty(position)) {
                    String newKey = (Double.valueOf(jsonMap.get("manufacturer").toString()).intValue()-1)+","+Double.valueOf(jsonMap.get("area").toString()).intValue()+","+Double.valueOf(jsonMap.get("position").toString()).intValue();
                    position = dataDictMap.get(newKey);
                    if(StringUtils.isEmpty(position)){
                        position = "pos-"+key;
                        log.info("key={},code={}",key,jsonMap.get("code").toString());
                    }
                }
                fireDevice.setPosition(position);
                Object codeObj = jsonMap.get("code");
                if(codeObj != null){
                    String code =codeObj.toString().replaceAll("–","-");
                    fireDevice.setCode(code);
                }else{
                    dirtyCount++;
                    continue;
                }
                Object buildDate = jsonMap.get("buildDate");
                if(buildDate != null){
                    Date gmtBuild = org.apache.commons.lang3.time.DateUtils.parseDate(buildDate.toString().replaceAll("–","-"), DatePattern.yyyy_MM.getPattern());
                    fireDevice.setGmtBuild(gmtBuild);
                }

                Object auditTime = jsonMap.get("auditTime");
                if(auditTime != null){
                    String auditTimeStr = auditTime.toString();
                    Date gmtAudit = DateUtils.parse(auditTimeStr, DateTimePattern.yyyyMMddHHmmss);
                    fireDevice.setGmtAudit(gmtAudit);
                }

                Object auditUserId = jsonMap.get("auditUserId");
                if(auditUserId != null){
                    Long userId = idMap.get(auditUserId.toString());
                    fireDevice.setAuditUserId(userId);
                }

                Object memo = jsonMap.get("memo");
                if(memo != null){
                    fireDevice.setMemo(memo.toString());
                }
                String gmtCreate = jsonMap.get("gmtCreate").toString();
                Date gmtCreateDate = DateUtils.parse(gmtCreate, DateTimePattern.yyyyMMddHHmmss);
                fireDevice.setGmtCreate(gmtCreateDate);


                String gmtModify = jsonMap.get("gmtModify").toString();
                Date gmtModifyDate = DateUtils.parse(gmtModify, DateTimePattern.yyyyMMddHHmmss);
                fireDevice.setGmtModified(gmtModifyDate);

                try{
                    fireDeviceService.save(fireDevice);
                }catch (Exception e){
                    repeatCount++;
                    FireDeviceVo fireDeviceVo = fireDeviceService.findByCode(fireDevice.getCode());
                    BeanUtils.beanCopy(fireDeviceVo,fireDevice);
                    FireDevice newFireDevice = BeanUtils.beanCopy(fireDeviceVo, FireDevice.class);
                    fireDeviceService.save(newFireDevice);
                    log.info("fireDevice={}",fireDevice);
                }
//            fireDevice.setGmtModified();
//            fireDevice.setDelState();


            }
            log.info("repeatCount={},dirtyCount={}",repeatCount,dirtyCount);

        }catch (Exception e){
            throw new RuntimeException(e);
        }


    }
}
